package com.indexingsystem.db.mongoDB.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.bson.Document;
import org.bson.conversions.Bson;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.indexingsystem.boss.Vo.BooksTableVo;
import com.indexingsystem.boss.Vo.BooksVo;
import com.indexingsystem.boss.entity.AuditLogs;
import com.indexingsystem.boss.entity.Books;
import com.indexingsystem.boss.entity.DhResourceauditlogs;
import com.indexingsystem.boss.entity.DhTodayStorageInfos;
import com.indexingsystem.boss.entity.ResCategoryRelations;
import com.indexingsystem.boss.entity.ResourceRelations;
import com.indexingsystem.boss.entity.Resources;
import com.indexingsystem.boss.entity.SpecialResourceDatas;
import com.indexingsystem.boss.logback.LogCvt;
import com.indexingsystem.boss.utils.JsonUtils;
import com.indexingsystem.db.mongoDB.MongoManager;
import com.indexingsystem.db.mongoDB.comon.MongoDBUtils;
import com.indexingsystem.db.mongoDB.comon.MongoTableName;
import com.indexingsystem.db.mongoDB.po.BooksResourceMongoVo;
import com.mongodb.BasicDBObject;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.UpdateOptions;

/**
 * 存储图书\绘本结构mongo内存操作实现类.
 * 
 * @author Administrator
 * 
 */
public class BooksResourceMongo {

	/**
	 * 入库管理图书\绘本资源mongo新增单条数据.
	 * 
	 * @param articlesResourceMongoVo
	 * @throws Exception
	 */
	public static void addBooks(BooksResourceMongoVo booksResourceMongoVo, String institutionId) throws Exception {
		MongoManager manager = new MongoManager();
		LogCvt.debug( MongoTableName.DH_BOOKS_RESOURCE + "添加 ------->" + com.alibaba.fastjson.JSON.toJSONString( booksResourceMongoVo, true ) );
		if (null != booksResourceMongoVo) {
			Document mainDocument = new Document();
			mainDocument.put( "_id", booksResourceMongoVo.getResId() );
			mainDocument.put( "resId", booksResourceMongoVo.getResId() );
			mainDocument.put( "resTypeId", booksResourceMongoVo.getResTypeId() );
			mainDocument.put( "resTable", booksResourceMongoVo.getResTable() );
			mainDocument.put( "institutionId", institutionId );

			Document booksDoc = MongoDBUtils.transform2Doc( booksResourceMongoVo.getBooks() );
			mainDocument.put( "books", booksDoc );

			Document resourcesDoc = MongoDBUtils.transform2Doc( booksResourceMongoVo.getResources() );
			mainDocument.put( "resources", resourcesDoc );

			Document resourceauditlogsDoc = MongoDBUtils.transform2Doc( booksResourceMongoVo.getResourceauditlogs() );
			mainDocument.put( "resourceauditlogs", resourceauditlogsDoc );

			Document auditLogsDoc = MongoDBUtils.transform2Doc( booksResourceMongoVo.getAuditLogs() );
			mainDocument.put( "auditLogs", auditLogsDoc );

			Document todayStorageInfosDoc = MongoDBUtils.transform2Doc( booksResourceMongoVo.getTodayStorageInfos() );
			mainDocument.put( "todayStorageInfos", todayStorageInfosDoc );

			List<Document> specialResourceDatasDocList = new ArrayList<Document>();
			if (null != booksResourceMongoVo.getDhSpecialResourceDatasList() && booksResourceMongoVo.getDhSpecialResourceDatasList().size() > 0) {
				for (SpecialResourceDatas specialResourceDatas : booksResourceMongoVo.getDhSpecialResourceDatasList()) {
					Document specialResourceDatasDoc = MongoDBUtils.transform2Doc( specialResourceDatas );
					specialResourceDatasDocList.add( specialResourceDatasDoc );
				}
			}
			mainDocument.put( "dhSpecialResourceDatasList", specialResourceDatasDocList );
			List<Document> dhResourceRelationsDocList = new ArrayList<Document>();
			if (null != booksResourceMongoVo.getDhResourceRelationsList() && booksResourceMongoVo.getDhResourceRelationsList().size() > 0) {
				for (ResourceRelations resourceRelations : booksResourceMongoVo.getDhResourceRelationsList()) {
					Document resourceRelationsDoc = MongoDBUtils.transform2Doc( resourceRelations );
					dhResourceRelationsDocList.add( resourceRelationsDoc );
				}
			}
			mainDocument.put( "dhResourceRelationsList", dhResourceRelationsDocList );

			List<Document> resCategoryRelationsDocList = new ArrayList<Document>();
			if (null != booksResourceMongoVo.getResCategoryRelationsList() && booksResourceMongoVo.getResCategoryRelationsList().size() > 0) {
				for (ResCategoryRelations resourceCategoryRelations : booksResourceMongoVo.getResCategoryRelationsList()) {
					Document resCategoryRelationsDoc = MongoDBUtils.transform2Doc( resourceCategoryRelations );
					resCategoryRelationsDocList.add( resCategoryRelationsDoc );
				}
			}
			mainDocument.put( "resCategoryRelationsList", resCategoryRelationsDocList );

			manager.add( mainDocument, MongoTableName.DH_BOOKS_RESOURCE );
		}
	}

	/**
	 * 入库管理单一修改图书\绘本资源mongo修改.
	 * 
	 * @param articlesResourceMongoVo
	 * @throws Exception
	 */
	public static void updateBooks(BooksResourceMongoVo booksResourceMongoVo, String institutionId) throws Exception {
		MongoManager manager = new MongoManager();
		LogCvt.debug( MongoTableName.DH_BOOKS_RESOURCE + "修改 ------->" + com.alibaba.fastjson.JSON.toJSONString( booksResourceMongoVo, true ) );
		if (null != booksResourceMongoVo) {
			Document mainDocument = new Document();
			mainDocument.put( "resId", booksResourceMongoVo.getResId() );
			mainDocument.put( "resTypeId", booksResourceMongoVo.getResTypeId() );
			mainDocument.put( "resTable", booksResourceMongoVo.getResTable() );
			mainDocument.put( "institutionId", institutionId );

			Document articlesDoc = MongoDBUtils.transform2Doc( booksResourceMongoVo.getBooks() );
			mainDocument.put( "books", articlesDoc );

			Document resourcesDoc = MongoDBUtils.transform2Doc( booksResourceMongoVo.getResources() );
			mainDocument.put( "resources", resourcesDoc );

			Document resourceauditlogsDoc = MongoDBUtils.transform2Doc( booksResourceMongoVo.getResourceauditlogs() );
			mainDocument.put( "resourceauditlogs", resourceauditlogsDoc );

			Document auditLogsDoc = MongoDBUtils.transform2Doc( booksResourceMongoVo.getAuditLogs() );
			mainDocument.put( "auditLogs", auditLogsDoc );

			Document todayStorageInfosDoc = MongoDBUtils.transform2Doc( booksResourceMongoVo.getTodayStorageInfos() );
			mainDocument.put( "todayStorageInfos", todayStorageInfosDoc );

			List<Document> specialResourceDatasDocList = new ArrayList<Document>();
			if (null != booksResourceMongoVo.getDhSpecialResourceDatasList() && booksResourceMongoVo.getDhSpecialResourceDatasList().size() > 0) {
				for (SpecialResourceDatas specialResourceDatas : booksResourceMongoVo.getDhSpecialResourceDatasList()) {
					Document specialResourceDatasDoc = MongoDBUtils.transform2Doc( specialResourceDatas );
					specialResourceDatasDocList.add( specialResourceDatasDoc );
				}
			}
			mainDocument.put( "dhSpecialResourceDatasList", specialResourceDatasDocList );

			List<Document> dhResourceRelationsDocList = new ArrayList<Document>();
			if (null != booksResourceMongoVo.getDhResourceRelationsList() && booksResourceMongoVo.getDhResourceRelationsList().size() > 0) {
				for (ResourceRelations resourceRelations : booksResourceMongoVo.getDhResourceRelationsList()) {
					Document resourceRelationsDoc = MongoDBUtils.transform2Doc( resourceRelations );
					dhResourceRelationsDocList.add( resourceRelationsDoc );
				}
			}
			mainDocument.put( "dhResourceRelationsList", dhResourceRelationsDocList );

			List<Document> resCategoryRelationsDocList = new ArrayList<Document>();
			if (null != booksResourceMongoVo.getResCategoryRelationsList() && booksResourceMongoVo.getResCategoryRelationsList().size() > 0) {
				for (ResCategoryRelations resourceCategoryRelations : booksResourceMongoVo.getResCategoryRelationsList()) {
					Document resCategoryRelationsDoc = MongoDBUtils.transform2Doc( resourceCategoryRelations );
					resCategoryRelationsDocList.add( resCategoryRelationsDoc );
				}
			}
			mainDocument.put( "resCategoryRelationsList", resCategoryRelationsDocList );

			UpdateOptions options = new UpdateOptions().upsert( true );
			Bson bson = Filters.and( Filters.eq( "resId", booksResourceMongoVo.getResId() ), Filters.eq( "institutionId", institutionId ) );
			Document doc = new Document( "$set", mainDocument );
			manager.updateOne( bson, doc, options, MongoTableName.DH_BOOKS_RESOURCE );
		}
	}

	/**
	 * 批量删除图书\绘本更新mongodb.
	 * 
	 * @param map
	 * @return
	 */
	public static void deleteBooksByIds(List<String> resIdList, String institutionId) {
		MongoManager manager = new MongoManager();
		Bson bson = Filters.and( Filters.in( "resId", resIdList ), Filters.eq( "institutionId", institutionId ) );
		manager.deleteAll( bson, MongoTableName.DH_BOOKS_RESOURCE );
	}

	/**
	 * 返回图书\绘本列表
	 * 
	 * @param map
	 * @return
	 */
	public static List<BooksTableVo> findBooksByPage(BooksVo booksVo, String institutionId) {
		MongoManager manager = new MongoManager();
		List<BooksTableVo> booksTableVoList = null;
		LogCvt.debug( MongoTableName.DH_BOOKS_RESOURCE + "查图书列表 ------->" );
		BasicDBObject basicDBObject = new BasicDBObject();
		basicDBObject.put( "resTable", "Books" );
		basicDBObject.put( "institutionId", institutionId );
		if (StringUtils.isNotBlank( booksVo.getQueryCriteria() )) {
			Pattern pattern = Pattern.compile( ".*" + booksVo.getQueryCriteria() + ".*", Pattern.CASE_INSENSITIVE );
			basicDBObject.put( "resources.resName", pattern );
		}
		if (null != booksVo.getStatus()) {
			basicDBObject.put( "resources.status", booksVo.getStatus() );
		}

		// 時間查詢
		if (booksVo.getStartPublishDate() != null && !booksVo.getStartPublishDate().equals( "" )) {

			BasicDBObject gt = new BasicDBObject( "$gte", booksVo.getStartPublishDate() );
			basicDBObject.put( "resources.publishDate", gt );
		}
		if (booksVo.getEndPublishDate() != null && !booksVo.getEndPublishDate().equals( "" )) {
			BasicDBObject lt = new BasicDBObject( "$lte", booksVo.getEndPublishDate() );
			basicDBObject.put( "resources.publishDate", lt );
		}

		if (StringUtils.isNotBlank( booksVo.getAuthor() )) {
			Pattern pattern = Pattern.compile( ".*" + booksVo.getAuthor() + ".*", Pattern.CASE_INSENSITIVE );
			basicDBObject.put( "books.author", pattern );
		}

		if (StringUtils.isNotBlank( booksVo.getTerminalCode() )) {
			basicDBObject.put( "dhSpecialResourceDatasList.terminalCode", booksVo.getTerminalCode() );
		}
		if (StringUtils.isNotBlank( booksVo.getPublisher() )) {
			Pattern pattern = Pattern.compile( ".*" + booksVo.getPublisher() + ".*", Pattern.CASE_INSENSITIVE );
			basicDBObject.put( "books.publisher", pattern );
		}

		if (StringUtils.isNotBlank( booksVo.getIsbn() )) {
			Pattern pattern = Pattern.compile( ".*" + booksVo.getIsbn() + ".*", Pattern.CASE_INSENSITIVE );
			basicDBObject.put( "books.isbn", pattern );
		}

		if (StringUtils.isNotBlank( booksVo.getAge() )) {
			Pattern pattern = Pattern.compile( ".*" + booksVo.getAge() + ".*", Pattern.CASE_INSENSITIVE );
			basicDBObject.put( "books.readingObject", pattern );
		}

		// 排序条件
		Document sortDocument = new Document();
		sortDocument.put( "resources.publishDate", -1 );
		// 不显示的字段
		Document fetchFields = new Document();
		fetchFields.put( "_id", 0 );
		fetchFields.put( "books", 1 );
		fetchFields.put( "resources", 1 );

		/* fetchFields.put( "dhSpecialResourceDatasList", 0 ); */
		List<Document> documentsList = manager.queryPages( MongoTableName.DH_BOOKS_RESOURCE, basicDBObject, sortDocument, fetchFields,
				booksVo.getPageNumber(), booksVo.getPageSize() );
		try {
			if (null != documentsList && documentsList.size() > 0) {
				booksTableVoList = new ArrayList<BooksTableVo>();
				for (Document document : documentsList) {
					BooksTableVo booksTableVo = new BooksTableVo();

					Books books = new Books();
					books = (Books) MongoDBUtils.setFieldValue( books, Document.parse( JsonUtils.toJson( document.get( "books" ) ) ) );
					if (null != books) {
						booksTableVo.setAge( books.getAge() );
						booksTableVo.setAlias( books.getAlias() );
						booksTableVo.setAuthor( books.getAuthor() );
						booksTableVo.setEdition( books.getEdition() );
						booksTableVo.setMaxAge( books.getMaxAge() );
						booksTableVo.setMinAge( books.getMinAge() );
						booksTableVo.setPageCount( books.getPageCount() );
						booksTableVo.setPublisher( books.getPublisher() );
						booksTableVo.setReadingObject( books.getReadingObject() );
						booksTableVo.setResId( books.getResId() );
						booksTableVo.setSereis( books.getSereis() );
					}

					Resources resources = new Resources();
					resources = (Resources) MongoDBUtils.setFieldValue( resources, Document.parse( JsonUtils.toJson( document.get( "resources" ) ) ) );
					if (null != resources) {
						booksTableVo.setPublishDate( resources.getPublishDate() );
						booksTableVo.setResName( resources.getResName() );
						booksTableVo.setStatus( resources.getStatus() );
						booksTableVo.setThumbnail( resources.getThumbnail() );
					}
					if (!booksTableVoList.contains( booksTableVo )) {
						booksTableVoList.add( booksTableVo );
					}
				}
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}

		LogCvt.debug( "查询 ArticlesTableVo 结果:" + JSON.toJSONString( booksTableVoList, true ) );
		return booksTableVoList;
	}

	/**
	 * 返回图书、绘本总数量.
	 * 
	 * @param map
	 * @return
	 */
	public static Integer findBooksMaxCount(BooksVo booksVo, String institutionId) {
		MongoManager manager = new MongoManager();
		LogCvt.debug( MongoTableName.DH_BOOKS_RESOURCE + "查图书列表总数量 ------->" );
		BasicDBObject basicDBObject = new BasicDBObject();
		basicDBObject.put( "resTable", "Books" );
		basicDBObject.put( "institutionId", institutionId );
		if (StringUtils.isNotBlank( booksVo.getQueryCriteria() )) {
			Pattern pattern = Pattern.compile( ".*" + booksVo.getQueryCriteria() + ".*", Pattern.CASE_INSENSITIVE );
			basicDBObject.put( "resources.resName", pattern );
		}
		if (null != booksVo.getStatus()) {
			basicDBObject.put( "resources.status", booksVo.getStatus() );
		}

		// 時間查詢
		if (booksVo.getStartPublishDate() != null && !booksVo.getStartPublishDate().equals( "" )) {

			BasicDBObject gt = new BasicDBObject( "$gte", booksVo.getStartPublishDate() );
			basicDBObject.put( "resources.publishDate", gt );
		}
		if (booksVo.getEndPublishDate() != null && !booksVo.getEndPublishDate().equals( "" )) {
			BasicDBObject lt = new BasicDBObject( "$lte", booksVo.getEndPublishDate() );
			basicDBObject.put( "resources.publishDate", lt );
		}

		if (StringUtils.isNotBlank( booksVo.getAuthor() )) {
			Pattern pattern = Pattern.compile( ".*" + booksVo.getAuthor() + ".*", Pattern.CASE_INSENSITIVE );
			basicDBObject.put( "books.author", pattern );
		}

		if (StringUtils.isNotBlank( booksVo.getTerminalCode() )) {
			basicDBObject.put( "dhSpecialResourceDatasList.terminalCode", booksVo.getTerminalCode() );
		}
		if (StringUtils.isNotBlank( booksVo.getPublisher() )) {
			Pattern pattern = Pattern.compile( ".*" + booksVo.getPublisher() + ".*", Pattern.CASE_INSENSITIVE );
			basicDBObject.put( "books.publisher", pattern );
		}

		if (StringUtils.isNotBlank( booksVo.getIsbn() )) {
			Pattern pattern = Pattern.compile( ".*" + booksVo.getIsbn() + ".*", Pattern.CASE_INSENSITIVE );
			basicDBObject.put( "books.isbn", pattern );
		}

		if (StringUtils.isNotBlank( booksVo.getAge() )) {
			Pattern pattern = Pattern.compile( ".*" + booksVo.getAge() + ".*", Pattern.CASE_INSENSITIVE );
			basicDBObject.put( "books.readingObject", pattern );
		}

		// 不显示的字段
		Document fetchFields = new Document();
		fetchFields.put( "_id", 0 );
		fetchFields.put( "resId", 1 );
		Integer maxCount = manager.queryAggregateListMaxCount( basicDBObject, MongoTableName.DH_BOOKS_RESOURCE );

		LogCvt.debug( "查询 findBooksMaxCount 总数量:" + maxCount );
		return maxCount;
	}

	/**
	 * 通过resId获取图书信息mongo缓存信息.
	 * 
	 * @param resId
	 * @return
	 */
	public static BooksResourceMongoVo selectBooksInfoByresId(String resId, String institutionId) throws Exception {
		MongoManager manager = new MongoManager();
		BooksResourceMongoVo booksResourceMongoVo = null;
		if (StringUtils.isNotBlank( resId )) {
			Bson bson = Filters.and( Filters.eq( "resId", resId ), Filters.eq( "institutionId", institutionId ) );
			LogCvt.info( MongoTableName.DH_BOOKS_RESOURCE + "通过resId获取图书信息条件:" + Arrays.asList( bson ).toString() );
			List<Document> documentsList = manager.queryAggregateList( bson, null, MongoTableName.DH_BOOKS_RESOURCE );
			if (null != documentsList && documentsList.size() > 0) {
				booksResourceMongoVo = new BooksResourceMongoVo();
				for (Document document : documentsList) {
					Resources resources = new Resources();
					resources = (Resources) MongoDBUtils.setFieldValue( resources, Document.parse( JsonUtils.toJson( document.get( "resources" ) ) ) );
					if (null != resources) {
						booksResourceMongoVo.setResources( resources );
					}

					Books books = new Books();
					books = (Books) MongoDBUtils.setFieldValue( books, Document.parse( JsonUtils.toJson( document.get( "books" ) ) ) );
					if (null != books) {
						booksResourceMongoVo.setBooks( books );
					}

					DhResourceauditlogs resourceauditlogs = new DhResourceauditlogs();
					resourceauditlogs = (DhResourceauditlogs) MongoDBUtils.setFieldValue( resourceauditlogs,
							Document.parse( JsonUtils.toJson( document.get( "resourceauditlogs" ) ) ) );
					if (null != resourceauditlogs) {
						booksResourceMongoVo.setResourceauditlogs( resourceauditlogs );
					}

					AuditLogs auditLogs = new AuditLogs();
					auditLogs = (AuditLogs) MongoDBUtils.setFieldValue( auditLogs, Document.parse( JsonUtils.toJson( document.get( "auditLogs" ) ) ) );
					if (null != auditLogs) {
						booksResourceMongoVo.setAuditLogs( auditLogs );
					}

					DhTodayStorageInfos todayStorageInfos = new DhTodayStorageInfos();
					todayStorageInfos = (DhTodayStorageInfos) MongoDBUtils.setFieldValue( todayStorageInfos,
							Document.parse( JsonUtils.toJson( document.get( "todayStorageInfos" ) ) ) );
					if (null != todayStorageInfos) {
						booksResourceMongoVo.setTodayStorageInfos( todayStorageInfos );
					}

					List<SpecialResourceDatas> dhSpecialResourceDatasList = new ArrayList<SpecialResourceDatas>();
					dhSpecialResourceDatasList = JSONArray.parseArray( JsonUtils.toJson( document.get( "dhSpecialResourceDatasList" ) ),
							SpecialResourceDatas.class );
					if (null != dhSpecialResourceDatasList && dhSpecialResourceDatasList.size() > 0) {
						booksResourceMongoVo.setDhSpecialResourceDatasList( dhSpecialResourceDatasList );
					}

					List<ResourceRelations> dhResourceRelationsList = new ArrayList<ResourceRelations>();
					dhResourceRelationsList = JSONArray.parseArray( JsonUtils.toJson( document.get( "dhResourceRelationsList" ) ),
							ResourceRelations.class );
					if (null != dhResourceRelationsList && dhResourceRelationsList.size() > 0) {
						booksResourceMongoVo.setDhResourceRelationsList( dhResourceRelationsList );
					}

					List<ResCategoryRelations> resCategoryRelationsList = new ArrayList<ResCategoryRelations>();
					resCategoryRelationsList = JSONArray.parseArray( JsonUtils.toJson( document.get( "resCategoryRelationsList" ) ),
							ResCategoryRelations.class );
					if (null != resCategoryRelationsList && resCategoryRelationsList.size() > 0) {
						booksResourceMongoVo.setResCategoryRelationsList( resCategoryRelationsList );
					}
				}
			}
		}
		return booksResourceMongoVo;
	}

	/**
	 * 通过resId获取图书信息mongo缓存信息.
	 * 
	 * @param resId
	 * @return
	 */
	public static List<BooksResourceMongoVo> selectBooksInfoListByresId(List<String> resIdList, String institutionId) throws Exception {
		MongoManager manager = new MongoManager();
		List<BooksResourceMongoVo> booksResourceMongoVoList = null;
		if (null != resIdList && resIdList.size() > 0) {
			Bson bson = Filters.and( Filters.eq( "resId", resIdList ), Filters.eq( "institutionId", institutionId ) );
			LogCvt.info( MongoTableName.DH_BOOKS_RESOURCE + "通过resId获取图书信息条件:" + Arrays.asList( bson ).toString() );
			List<Document> documentsList = manager.queryAggregateList( bson, null, MongoTableName.DH_BOOKS_RESOURCE );
			if (null != documentsList && documentsList.size() > 0) {
				booksResourceMongoVoList = new ArrayList<BooksResourceMongoVo>();
				for (Document document : documentsList) {
					BooksResourceMongoVo booksResourceMongoVo = new BooksResourceMongoVo();
					Resources resources = new Resources();
					resources = (Resources) MongoDBUtils.setFieldValue( resources, Document.parse( JsonUtils.toJson( document.get( "resources" ) ) ) );
					if (null != resources) {
						booksResourceMongoVo.setResources( resources );
					}

					Books books = new Books();
					books = (Books) MongoDBUtils.setFieldValue( books, Document.parse( JsonUtils.toJson( document.get( "books" ) ) ) );
					if (null != books) {
						booksResourceMongoVo.setBooks( books );
					}

					DhResourceauditlogs resourceauditlogs = new DhResourceauditlogs();
					resourceauditlogs = (DhResourceauditlogs) MongoDBUtils.setFieldValue( resourceauditlogs,
							Document.parse( JsonUtils.toJson( document.get( "resourceauditlogs" ) ) ) );
					if (null != resourceauditlogs) {
						booksResourceMongoVo.setResourceauditlogs( resourceauditlogs );
					}

					AuditLogs auditLogs = new AuditLogs();
					auditLogs = (AuditLogs) MongoDBUtils.setFieldValue( auditLogs, Document.parse( JsonUtils.toJson( document.get( "auditLogs" ) ) ) );
					if (null != auditLogs) {
						booksResourceMongoVo.setAuditLogs( auditLogs );
					}

					DhTodayStorageInfos todayStorageInfos = new DhTodayStorageInfos();
					todayStorageInfos = (DhTodayStorageInfos) MongoDBUtils.setFieldValue( todayStorageInfos,
							Document.parse( JsonUtils.toJson( document.get( "todayStorageInfos" ) ) ) );
					if (null != todayStorageInfos) {
						booksResourceMongoVo.setTodayStorageInfos( todayStorageInfos );
					}

					List<SpecialResourceDatas> dhSpecialResourceDatasList = new ArrayList<SpecialResourceDatas>();
					dhSpecialResourceDatasList = JSONArray.parseArray( JsonUtils.toJson( document.get( "dhSpecialResourceDatasList" ) ),
							SpecialResourceDatas.class );
					if (null != dhSpecialResourceDatasList && dhSpecialResourceDatasList.size() > 0) {
						booksResourceMongoVo.setDhSpecialResourceDatasList( dhSpecialResourceDatasList );
					}

					List<ResourceRelations> dhResourceRelationsList = new ArrayList<ResourceRelations>();
					dhResourceRelationsList = JSONArray.parseArray( JsonUtils.toJson( document.get( "dhResourceRelationsList" ) ),
							ResourceRelations.class );
					if (null != dhResourceRelationsList && dhResourceRelationsList.size() > 0) {
						booksResourceMongoVo.setDhResourceRelationsList( dhResourceRelationsList );
					}

					List<ResCategoryRelations> resCategoryRelationsList = new ArrayList<ResCategoryRelations>();
					resCategoryRelationsList = JSONArray.parseArray( JsonUtils.toJson( document.get( "resCategoryRelationsList" ) ),
							ResCategoryRelations.class );
					if (null != resCategoryRelationsList && resCategoryRelationsList.size() > 0) {
						booksResourceMongoVo.setResCategoryRelationsList( resCategoryRelationsList );
					}

					if (!booksResourceMongoVoList.contains( booksResourceMongoVo )) {
						booksResourceMongoVoList.add( booksResourceMongoVo );
					}
				}
			}
		}
		return booksResourceMongoVoList;
	}
}